<template>
    <div class="app-container">
      <div class="Search">
        <!--工具条-->
        <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
          <el-form :inline="true" :model="query">
            <el-form-item v-has="'PLATFROM_TENANT_QUERY'">
              <el-cascader ref="tenantTree" placeholder="所属租户" :props="tenantProps" :options="tenantOptions" @change="selectTenant" clearable collapse-tags filterable></el-cascader>
            </el-form-item>
            <el-form-item>
              <el-cascader ref="organTree" placeholder="所属组织" :props="props" :options="organOptions" @change="selectOrgan" collapse-tags clearable filterable></el-cascader>
            </el-form-item>
            <el-form-item>
              <el-cascader ref="goodsTypeTree" placeholder="商品分类" :props="goodsTypeTreeProps" :options="goodsTypeTreeOptionData" @change="selectGoodsType" filterable></el-cascader>
            </el-form-item>
            <el-form-item>
              <el-input v-model="query.params.goodsName" placeholder="商品名称" clearable />
            </el-form-item>
            <el-form-item>
              <el-cascader ref="supplierTree" placeholder="供应商" :props="supplierProps" :options="supplierOptions" @change="selectSupplier" clearable collapse-tags filterable></el-cascader>
            </el-form-item>
            <el-form-item>
              <el-input v-model="query.params.goodsDescribe" placeholder="商品描述" clearable />
            </el-form-item>
            <el-form-item>
              <el-input v-model="query.params.productionPlace" placeholder="商品产地" clearable />
            </el-form-item>
            <el-form-item>
              <el-button v-has="'GOODS_LIST'" type="primary" icon="el-icon-search" size="mini" @click="fetchData">查询</el-button>
            </el-form-item>
            <el-form-item>
              <el-button v-has="'GOODS_ADD'" type="success" icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
            </el-form-item>
          </el-form>
        </el-col>
      </div>
      <div class="block">
        <el-table v-loading="listLoading" :data="list" element-loading-text="Loading" border fit highlight-current-row>
          <el-table-column align="center" label="序号" width="95">
            <template slot-scope="scope">
              {{ scope.$index }}
            </template>
          </el-table-column>
          <el-table-column label="所属机构" width="110" prop="organId" :formatter="translateOrgan" />
          <el-table-column label="商品分类" width="110">
            <template slot-scope="scope">
              {{ scope.row.goodsTypeId }}
            </template>
          </el-table-column>
          <el-table-column label="商品名称" width="110">
            <template slot-scope="scope">
              {{ scope.row.goodsName }}
            </template>
          </el-table-column>
          <el-table-column label="供应商" width="110">
            <template slot-scope="scope">
              {{ scope.row.supplierId }}
            </template>
          </el-table-column>
          <el-table-column label="商品图片url" width="110">
            <template slot-scope="scope">
              <el-image style="width: 100px; height: 100px" :src="scope.row.goodsImg">
              </el-image>
            </template>
          </el-table-column>
          <el-table-column label="商品描述" width="110">
            <template slot-scope="scope">
              {{ scope.row.goodsDescribe }}
            </template>
          </el-table-column>
          <el-table-column label="商品规格单位" width="110">
            <template slot-scope="scope">
              {{ scope.row.unit }}
            </template>
          </el-table-column>
          <el-table-column label="商品规格值" width="110">
            <template slot-scope="scope">
              {{ scope.row.unitValue }}
            </template>
          </el-table-column>
          <el-table-column label="商品产地" width="110">
            <template slot-scope="scope">
              {{ scope.row.productionPlace }}
            </template>
          </el-table-column>
          <el-table-column label="备注" width="110">
            <template slot-scope="scope">
              {{ scope.row.remark }}
            </template>
          </el-table-column>
          <el-table-column fixed="right" align="center" prop="created_at" label="操作" width="200">
            <template slot-scope="scope">
              <el-link v-has="'GOODS_EDIT'" icon="el-icon-edit" type="warning" style="cursor: pointer;" @click="handleEdit(scope.$index, scope.row)">
                修改
              </el-link>
              <el-link v-has="'GOODS_REMOVE'" class="el-icon-delete" type="danger" @click="handleDelete(scope.$index, scope.row)">
                删除
              </el-link>
              <el-link v-has="'GOODS_IMG_EDIT'" icon="el-icon-picture-outline-round" type="success" @click="handleGoodsImgAdd(scope.$index, scope.row)">
                添加图片
              </el-link>
              <el-link v-has="'SHOW_GOODS_IMG_BY_GOODS'" type="info" icon="el-icon-picture" @click="handleGetGoodsImgs(scope.$index, scope.row)">
                查看图片
              </el-link>
              <el-link v-has="'GOODS_PRICE_EDIT'" icon="el-icon-money" type="success" @click="handleAddGoodsPrice(scope.$index, scope.row)">
                添加定价
              </el-link>
              <el-link v-has="'GOODS_PRICE_LIST'" icon="el-icon-coin" type="info" @click="handleShowGoodsPriceList(scope.$index, scope.row)">
                查看定价情况
              </el-link>
              <el-link v-has="'handleAssignToOrgan'" icon="el-icon-coin" type="info" @click="handleAssignToOrgan(scope.$index, scope.row)">
                分配给组织
              </el-link>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="block">
        <el-pagination :current-page="currentPage" :page-sizes="[10, 20, 30, 40]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
      </div>
      <div class="block">
        <!--弹框-->
        <el-dialog :title="titleMap[dialogStatus]" :visible.sync="dialogFormGoodsImgAddVisible">
          <el-form :model="form">
            <el-form-item v-if="addForGoodsImgVisible" label="主键">
              <el-input v-model="goodsImg.id" placeholder="主键" disabled auto-complete="off" />
            </el-form-item>
            <el-form-item label="关联商品">
              <el-input disabled v-model="goodsImg.goodsId" placeholder="关联商品" auto-complete="off" />
            </el-form-item>
            <el-form-item label="图片所在地址">
              <el-upload class="upload-demo" action="/api/file.allService/FileService/uploadFile" :headers="uploadHeader" :with-credentials="true"  :on-preview="handlePreview" :on-remove="handleRemove" :before-remove="beforeRemove" multiple :data='fileUloadParams' :on-success="uploadImgOnSuccess" name="file" :limit="1" :on-exceed="handleExceed" :file-list="fileList">
                <el-button size="small" type="primary">点击上传</el-button>
                <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
              </el-upload>
            </el-form-item>
            <el-form-item label="图片类型">
              <el-select v-model="goodsImg.imgType" placeholder="图片类型" style="width: 100%">
                <el-option v-for="item in query.googsImgTypeOptions" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="目录">
              <el-input v-model="goodsImg.folder" placeholder="目录" auto-complete="off" />
            </el-form-item>
            <el-form-item label="排序">
              <el-select v-model="goodsImg.sort" placeholder="排序" style="width: 100%">
                <el-option v-for="item in query.options" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-table-column label="所属组织" width="110" prop="organId" :formatter="translateOrgan" />
            <el-form-item label="组织路径">
              <el-input v-model="goodsImg.organPath" placeholder="组织路径" auto-complete="off" />
            </el-form-item>
            <el-form-item label="备注">
              <el-input v-model="goodsImg.remark" placeholder="备注" auto-complete="off" />
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormGoodsImgAddVisible = false">取 消</el-button>
            <el-button type="primary" @click="handleGoodsImgEditSave">确 定</el-button>
          </div>
        </el-dialog>
      </div>
      <div class="block">
        <!--弹框-->
        <el-dialog :title="'查看商品价格'" width="88%" :visible.sync="dialogShowGoodsPriceListAddVisible">
            <div class="block">
              <el-form :inline="true" :model="query">
              <el-form-item>
                <el-button v-has="'GOODS_ADD'" type="success" icon="el-icon-plus" size="mini" @click="handleAddGoodsPrice">新增</el-button>
              </el-form-item>
            </el-form>
            <el-table v-loading="listLoading" :data="goodsPriceList" element-loading-text="Loading" border fit highlight-current-row>
              <el-table-column align="center" label="序号" width="50">
                <template slot-scope="scope">
                  {{ scope.$index }}
                </template>
              </el-table-column>
              <el-table-column label="所属组织" width="110" prop="organId" :formatter="translateOrgan" />
              <el-table-column label="关联商品" width="110">
                <template slot-scope="scope">
                  {{ scope.row.goodsId }}
                </template>
              </el-table-column>
              <el-table-column label="商品名称" width="110">
                <template slot-scope="scope">
                  {{ scope.row.goodsName }}
                </template>
              </el-table-column>
              <el-table-column label="商品编码" width="110">
                <template slot-scope="scope">
                  {{ scope.row.goodsCode }}
                </template>
              </el-table-column>
              <el-table-column label="价格(单位：分)" width="110">
                <template slot-scope="scope">
                  {{ scope.row.price }}
                </template>
              </el-table-column>
              <el-table-column label="商品成本(单位：分)" width="110">
                <template slot-scope="scope">
                  {{ scope.row.costPrice }}
                </template>
              </el-table-column>
              <el-table-column label="折扣价格(单位：分)" width="110">
                <template slot-scope="scope">
                  {{ scope.row.discountPrice }}
                </template>
              </el-table-column>
              <el-table-column label="建议价格(单位：分)" width="110">
                <template slot-scope="scope">
                  {{ scope.row.suggestedRetailPrice }}
                </template>
              </el-table-column>
              <el-table-column label="备注" width="110">
                <template slot-scope="scope">
                  {{ scope.row.remark }}
                </template>
              </el-table-column>
              <el-table-column fixed="right" align="center" prop="created_at" label="操作">
                <template slot-scope="scope">
                  <el-link type="primary" style="cursor: pointer;" icon="edit" @click="handleModifyGoodsPrice(scope.$index, scope.row)">
                    修改
                  </el-link>
                  <el-link v-if="!scope.row.isSet" type="danger" icon="delete" style="cursor: pointer;" @click="handleDeleteGoodsPrice(scope.$index, scope.row)">
                    删除
                  </el-link>
                  <el-link v-has="'DICTIONARYORGAN_ASSIGNEDDICTIONARY'" type="info" style="cursor: pointer;" @click="handleBindGoodsSpecification(scope.$index, scope.row)">
                    绑定商品规格
                  </el-link>
                </template>
              </el-table-column>
            </el-table>
          </div>
          <div class="block">
            <el-pagination :current-page="query.goodsPrice.currentPage" :page-sizes="[10, 20, 30, 40]" :page-size="query.goodsPrice.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="query.goodsPrice.total" @size-change="handleGoodsPriceSizeChange" @current-change="handleGoodsPriceCurrentChange" />
          </div>
          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogShowGoodsPriceListAddVisible = false">取 消</el-button>
            <el-button type="primary" @click="handleGoodsImgEditSave">确 定</el-button>
          </div>
        </el-dialog>
      </div>
      <div class="block">
        <!--弹框-->
        <el-dialog :title="titleMap[dialogStatus]" :visible.sync="dialogFormVisible">
  
          <el-form :model="form" :rules="goodsRule" ref="goodsForm">
            <el-form-item v-if="addForVisible" label="商品id"  ref="">
              <el-input v-model="form.id" placeholder="商品id" disabled auto-complete="off" />
            </el-form-item>
            <el-form-item v-has="'PLATFROM_TENANT_QUERY'" prop="tenantId" label="所属租户" placeholder="所属租户" required>
              <el-cascader v-model="form.tenantId" ref="tenantTreeForm" placeholder="所属租户" :props="tenantProps" :options="tenantOptions" @change="chooseTenantForm" style="width:100%" clearable collapse-tags filterable></el-cascader>
            </el-form-item>
            <el-form-item required prop="organId"  label="所属组织">
              <el-cascader v-model="form.organId" ref="organTreeForm" placeholder="所属组织" :props="props" :options="organFormOptions" @change="chooseOrganForm" style="width:100%" collapse-tags filterable></el-cascader>
            </el-form-item>
            <el-form-item  required prop="goodsName" label="商品名称">
              <el-input v-model="form.goodsName" placeholder="商品名称" auto-complete="off" />
            </el-form-item>
            <el-form-item required prop="goodsTypeId" label="商品分类">
              <el-cascader v-model="form.goodsTypeId" ref="goodsTypeTreeForm" style="width:100%" placeholder="商品分类" :props="goodsTypeTreeProps" :options="goodsTypeTreeOptionData" @change="getGoodsType(form)" collapse-tags filterable></el-cascader>
            </el-form-item>
            <el-form-item required prop="supplierId" label="供应商">
              <el-cascader v-model="form.supplierId" ref="applyerTree" style="width:100%" placeholder="商品分类" :props="props" :options="supplierOptions" @change="getSupplier" collapse-tags filterable></el-cascader>
            </el-form-item>
            <el-form-item required prop="goodsImg" label="商品图片url">
              <el-upload class="upload-demo" action="/api/file.allService/FileService/uploadFile" :headers="uploadHeader" :with-credentials="true" :on-preview="handlePreview" :on-remove="handleRemove" :before-remove="beforeRemove" multiple :data='fileUloadParams' :on-success="uploadFileOnSuccess" name="file" :limit="1" :on-exceed="handleExceed" :file-list="fileList">
                <el-button size="small" type="primary">点击上传</el-button>
                <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
              </el-upload>
            </el-form-item>
            <el-form-item  required prop="productionPlace"  label="商品产地">
              <el-input v-model="form.productionPlace" placeholder="商品产地" auto-complete="off" />
            </el-form-item>
            <el-form-item  required prop="goodsDescribe"  label="商品描述">
              <el-input v-model="form.goodsDescribe" placeholder="商品描述" auto-complete="off" />
            </el-form-item>
            <el-form-item required prop="measurementType"  label="商品计量类型">
              <el-select v-model="form.measurementType" style="width:100%" @change="handleInitMeasurementUnitOptions(form)" placeholder="请选择商品计量单位">
                <el-option v-for="item in query.measurementTypeOptions"  :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>          
            </el-form-item>
            <el-form-item  required prop="unitValue" label="商品数量">
              <el-input v-model="form.unitValue" placeholder="商品数量" auto-complete="off" />
            </el-form-item>
            <el-form-item  required prop="unit" label="商品计量单位">
              <el-select v-model="form.unit" style="width:100%" placeholder="商品计量单位">
                <el-option v-for="item in query.measurementUnitOptions" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="备注">
              <el-input v-model="form.remark" placeholder="备注" auto-complete="off" />
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="handleEditSave">确 定</el-button>
          </div>
        </el-dialog>
      </div>
      <div class="block">
        <!--弹框-->
        <el-dialog :title="titleMap[dialogStatus]" :visible.sync="dialogForGoodsImgVisible">
          <div class="demo-image__lazy">
            <el-image v-for="url in goodsImgUrls" :key="url" :src="url" lazy></el-image>
          </div>
        </el-dialog>
      </div>
      <div class="block">
        <!--弹框-->
        <el-dialog :title="'添加商品SKU【商品售价】'" :visible.sync="dialogFormGoodsPriceVisible">
          <el-form :model="goodsPrice" :rules="goodsPriceRule" ref="goodsPriceForm">
            <el-form-item v-if="addForGoodsPriceVisible"  label="SKU编码">
              <el-input v-model="goodsPrice.id" disabled placeholder="SKU编码" auto-complete="off" />
            </el-form-item>
            <el-form-item label="关联商品" required prop="goodsId" >
              <el-input disabled v-model="goodsPrice.goodsId" placeholder="关联商品" auto-complete="off" />
            </el-form-item>
            <el-form-item v-has="'PLATFROM_TENANT_QUERY'" label="所属租户"  required prop="tenantId" >
              <el-cascader v-model="goodsPrice.tenantId" ref="tenantTreeForm" placeholder="所属租户" :props="tenantProps" :options="tenantOptions" @change="chooseTenant(goodsPrice)" style="width:100%" clearable collapse-tags filterable></el-cascader>
            </el-form-item>
            <el-form-item label="所属组织" required prop="organId">
              <el-cascader v-model="goodsPrice.organId" ref="organTreeForm" placeholder="所属组织" :props="props" :options="organFormOptions" @change="chooseOrganForm" style="width:100%" collapse-tags filterable></el-cascader>
            </el-form-item>
            <el-form-item label="商品名称" required prop="goodsName">
              <el-input v-model="goodsPrice.goodsName" placeholder="SKU名称" auto-complete="off" />
            </el-form-item>
            <el-form-item label="销售域" required prop="isVending">
              <el-radio v-model="goodsPrice.isVending" label="0" border>商铺</el-radio>
              <el-radio v-model="goodsPrice.isVending" label="1" border>售卖机</el-radio>
            </el-form-item>
            <el-form-item label="商品分类" required prop="goodsTypeId">
              <el-cascader v-model="goodsPrice.goodsTypeId" ref="goodsTypeTreeForm" style="width:100%" placeholder="商品分类" :props="goodsTypeTreeProps" :options="goodsTypeTreeOptionData" @change="getGoodsType(goodsPrice)" collapse-tags filterable></el-cascader>
            </el-form-item>
            <el-form-item label="商品编码" required prop="goodsCode">
              <el-input v-model="goodsPrice.goodsCode" placeholder="SKU编码" auto-complete="off" />
            </el-form-item>
            <el-form-item label="价格(单位：分)" required prop="price">
              <el-input v-model="goodsPrice.price" placeholder="价格(单位：分)" auto-complete="off" />
            </el-form-item>
            <el-form-item label="折扣价格(单位：分)" required prop="discountPrice">
              <el-input v-model="goodsPrice.discountPrice" placeholder="价格(单位：分)" auto-complete="off" />
            </el-form-item>
            <el-form-item label="商品成本(单位：分)" required prop="costPrice">
              <el-input v-model="goodsPrice.costPrice" placeholder="价格(单位：分)" auto-complete="off" />
            </el-form-item>
            <el-form-item label="建议价格(单位：分)" required prop="suggestedRetailPrice">
              <el-input v-model="goodsPrice.suggestedRetailPrice" placeholder="价格(单位：分)" auto-complete="off" />
            </el-form-item>
            <el-form-item label="商品计量类型" required prop="measurementType">
              <el-select v-model="goodsPrice.measurementType" style="width:100%" @change="handleInitMeasurementUnitOptions(goodsPrice)" placeholder="请选择商品计量单位">
                <el-option v-for="item in query.measurementTypeOptions"  :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>          
            </el-form-item>
            <el-form-item label="SKU库存数" required prop="stockCount">
              <el-input v-model="goodsPrice.stockCount" placeholder="SKU库存数" auto-complete="off" />
            </el-form-item>
            <el-form-item label="SKU计量单位" required prop="unit">
              <el-select v-model="goodsPrice.unit" style="width:100%" placeholder="SKU计量单位">
                <el-option v-for="item in query.measurementUnitOptions" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
  
            <el-form-item label="备注">
              <el-input v-model="goodsPrice.remark" placeholder="备注" auto-complete="off" />
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormGoodsPriceVisible = false">取 消</el-button>
            <el-button type="primary" @click="handleAddGoodsPriceSave">确 定</el-button>
          </div>
        </el-dialog>
      </div>
      <div class="block">
        <!--弹框-->
        <el-dialog :title="titleMap[dialogStatus]" :visible.sync="dialogFormOrganVisible">
          <el-tree ref="assigneeTree" :data="organTree" :default-expand-all="true" :props="organTreeProps" :check-strictly="false" show-checkbox node-key="id" highlight-current />
          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormOrganVisible = false">取 消</el-button>
            <el-button type="primary" @click="getCheckedNodes">确 定</el-button>
          </div>
        </el-dialog>
      </div>
      <div class="block">
        <!--弹框-->
        <el-dialog :title="titleMap[dialogStatus]" width="78%" :visible.sync="dialogFormShowGoodsSpecificationVisible">
          <div class="Search">
            <!--工具条-->
            <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
              <el-form :inline="true" :model="query">
                <el-form-item>
                  <el-input v-model="goodsSpecification.parameterName" placeholder="参数名称" auto-complete="off" />
                </el-form-item>
                <el-form-item>
                  <el-button type="primary" @click="handleQueryGoodsTypeSpecification">查询</el-button>
                </el-form-item>
              </el-form>
            </el-col>
          </div>
          <el-table v-loading="listLoading" :data="goodsSpecificationList" element-loading-text="Loading" border fit highlight-current-row>
            <el-table-column type="expand" align="center" label="" width="58">
              <template slot-scope="scope">
                <el-table v-loading="listLoading" :data="goodsTypeSpecificationItemList" element-loading-text="Loading" border fit highlight-current-row>
                  <el-table-column align="center" label="序号" width="58">
                    <template slot-scope="scope">
                      {{ scope.$index }}
                    </template>
                  </el-table-column>
                  <el-table-column label="分类属性值" width="110">
                    <template slot-scope="scope">
                      {{ scope.row.specificationValue }}
                    </template>
                  </el-table-column>
                  <el-table-column label="备注">
                    <template slot-scope="scope">
                      {{ scope.row.remark }}
                    </template>
                  </el-table-column>
                </el-table>
                <div class="block">
                  <el-pagination :current-page="query.goodsSpecificationItem.currentPage" :page-sizes="[10, 20, 30, 40]" :page-size="query.goodsSpecificationItem.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="query.goodsSpecificationItem.total" @size-change="handleQueryItemValSizeChange" @current-change="handleQueryItemCurrentChange" />
                </div>
              </template>
            </el-table-column>
            <el-table-column align="center" label="序号" width="95">
              <template slot-scope="scope">
                {{ scope.$index }}
              </template>
            </el-table-column>
            <el-table-column label="规格组编号" width="110">
              <template slot-scope="scope">
                {{ scope.row.groupId }}
              </template>
            </el-table-column>
            <el-table-column label="参数名称" width="110">
              <template slot-scope="scope">
                {{ scope.row.parameterName }}
              </template>
            </el-table-column>
            <el-table-column label="显示区域" width="110">
              <template slot-scope="scope">
                {{ scope.row.displayArea }}
              </template>
            </el-table-column>
            <el-table-column label="商品分类编号" width="110">
              <template slot-scope="scope">
                {{ scope.row.goodsTypeId }}
              </template>
            </el-table-column>
            <el-table-column label="备注" width="110">
              <template slot-scope="scope">
                {{ scope.row.remark }}
              </template>
            </el-table-column>
            <el-table-column align="center" prop="created_at" label="操作">
              <template slot-scope="scope">
                <span class="el-tag el-tag--info el-tag--mini" style="cursor: pointer;" @click="handleEdit(scope.$index, scope.row)">
                  {{ scope.row.isSet?'保存':"修改" }}
                </span>
                <span v-if="!scope.row.isSet" class="el-tag el-tag--danger el-tag--mini" style="cursor: pointer;" @click="handleDelete(scope.$index, scope.row)">
                  删除
                </span>
                <span class="el-tag el-tag--danger el-tag--mini" style="cursor: pointer;" @click="handleAddGoodsTypeSpecificationItem(scope.$index, scope.row)">
                  添加规格项
                </span>
                <el-link v-has="'DICTIONARYORGAN_ASSIGNEDDICTIONARY'" type="info" style="cursor: pointer;" @click="handleShowAssignSpecification2OrganList(scope.$index, scope.row)">
                  指派给
                </el-link>
              </template>
            </el-table-column>
          </el-table>
          <div class="block">
            <el-pagination :current-page="query.goodsSpecification.currentPage" :page-sizes="[10, 20, 30, 40]" :page-size="query.goodsSpecification.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="query.goodsSpecification.total" @size-change="handleQueryGoodsSpecificationSizeChange" @current-change="handleQueryGoodsSpecificationCurrentChange" />
          </div>
          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormShowGoodsSpecificationVisible = false">取 消</el-button>
            <el-button type="primary" @click="handleGoodsSpecification2OrganSave">确 定</el-button>
          </div>
        </el-dialog>
      </div>
    </div>
  </template>
  <script>
  import { getList, doDelete, doEdit, assign2Organs, queryGoodsAssignee as queryAlreadyAssignedOrgans } from '@/api/Goods/'
  import { doEdit as doUploadImg, getList as getGoodsImgs, getGoodsImgByGoods } from '@/api/GoodsImg/'
  import { queryAssigneeOrgan, querySubordinateOrgan } from '@/api/Organ'
  import { getGoodsTypeTree } from '@/api/GoodsType'
  import { getList as getGoodsPriceList, doDelete as deleteGoodsPrice, doEdit as saveGoodsPrice } from '@/api/GoodsPrice/'
  import { getDictionaryGroup } from '@/api/dictionary'
  
  import { getOrganId, getTenantId, getOrganPath, getCurrentLoginUserId, handleBuildTreeDataStruct, getSuperManagerId, getSelectedNodes, getSelectedNodesObject, getSystemErrorCode } from '@/api/utils'
  
  import { getTenantList, getToken,  getOrganList, getDictionary, translateOrganId2OrganName } from '@/utils/auth'
  import localStorageUtil from '@/utils/localStorageUtil'
  import sessionStorageUtil from '@/utils/sessionStorageUtil'
  
  export default {
    data() {
      return {
        list: [],
        listLoading: true,
        total: 5,
        currentPage: 1,
        pageSize: 10,
        dialogFormVisible: false,
        addForVisible: false,
        fileList: [],
        fileUloadParams: { organId: 1, createBy: 1 },
        dialogFormGoodsImgAddVisible: false,
        addForGoodsImgVisible: false,
        dialogForGoodsImgVisible: false,
        dialogFormGoodsPriceVisible: false,
        addForGoodsPriceVisible: false,
        dialogShowGoodsPriceListAddVisible: false,
        dialogFormOrganVisible: false,
        dialogFormShowGoodsSpecificationVisible: false,
        goodsImgUrls: [],
        goodsPriceList: [],
        organList: [],
        goodsSpecificationList: [],
        organTree: [],
        form: {
          id: '',
          organId: '',
          organPath: '',
          organName: '',
          goodsTypeId: '',
          goodsTypePath: '',
          goodsName: '',
          supplierId: '',
          goodsImg: '',
          goodsDescribe: '',
          unit: '',
          unitValue: '',
          productionPlace: '',
          sys: '',
          isDeleted: '',
          quote: '',
          createBy: '',
          createDate: '',
          updateBy: '',
          updateDate: '',
          measurementType:'',
          remark: '',
          assignee: {
            id: '',
            organPath: ''
          }
  
        },
        goodsImg: {
          id: '',
          goodsId: '',
          imgUrl: '',
          imgType: '',
          folder: '',
          sort: '',
          organId: '',
          organPath: '',
          createBy: '',
          createDate: '',
          updateBy: '',
          updateDate: '',
          isDeleted: '',
          remark: ''
        },
        goodsPrice: {
          id: '',
          goodsId: '',
          goodsName: '',
          goodsCode: '',
          organId: '',
          organPath: '',
          isDeleted: '',
          isVending: false,
          createBy: '',
          createDate: '',
          updateBy: '',
          updateDate: '',
          remark: '',
          price: '',
          costPrice: '',
          discountPrice: '',
          suggestedRetailPrice: ''
        },
        goodsSpecification: {
          id: '',
          groupId: '',
          displayArea: '',
          parameterName: '',
          goodsTypeId: '',
          organId: '',
          organPath: '',
          isDeleted: '',
          createBy: '',
          createDate: '',
          updateBy: '',
          updateDate: '',
          remark: ''
        },
        assign2Organs: {
          assignees: [],
          id: '',
          createBy: '',
          updateBy: ''
        },
        // 新增or编辑弹框标题(根据点击的新增or编辑按钮显示不同的标题)
        titleMap: {
          add: '新增',
          edit: '编辑',
          addGoodsImg: '添加商品图片',
          showGoodsImgs: '商品图片',
          assignOrgan: '选择需要指派的组织'
        },
        isClearable: true, // 可清空（可选）
        isAccordion: true, // 可收起（可选）
        valueId: null, // 初始ID（可选）
        props: { // 配置项（必选）
          value: 'id',
          label: 'organName',
          children: 'children',
          title: '组织',
          multiple: false,
          checkStrictly: true,
          emitPath: false
          // disabled:true
        },
        organTreeProps: {
          children: 'children',
          label: 'organName',
          url: 'url'
        },
        tenantProps: { // 配置项（必选）
          value: 'id',
          label: 'organName',
          children: 'children',
          title: '租户',
          multiple: false,
          checkStrictly: true,
          emitPath: false
          // disabled:true
        },
        supplierProps: { // 配置项（必选）
          value: 'id',
          label: 'organName',
          children: 'children',
          title: '租户',
          multiple: false,
          checkStrictly: true,
          emitPath: false
          // disabled:true
        },
        organFormOptions: [],
        tenantOptions: [],
        organOptions: [{ id: '1', parentId: '2', organName: '平台', children: [] }],
        supplierOptions: [{ id: '1', parentId: '2', organName: '平台', children: [] }],
        organTreeProps: {
          children: 'children',
          label: 'organName',
          url: 'url'
        },
        organQueryModel: 'selfAndSub',
        supplier: null, //供应商
        goodsType: null, //商品分类
        // // 新增or编辑弹框标题(根据点击的新增or编辑按钮显示不同的标题)
        optionData: [{ id: '1', parentId: '2', organName: '平台', children: [] }],
        clearable: true, // 可清空（可选）
        accordion: true, // 可收起（可选）
        goodsTypeValueId: null, // 初始ID（可选）
        goodsTypeTreeProps: { // 配置项（必选）
          value: 'id',
          label: 'typeName',
          children: 'children',
          checkStrictly: true,
          title: '组织'
          // disabled:true
        },
        goodsAssignees: {
          assignees: []
        },
        // // 新增or编辑弹框标题(根据点击的新增or编辑按钮显示不同的标题)
        dialogStatus: '',
        goodsTypeTreeOptionData: [{ id: '1', parentId: '2', typeName: '平台', children: [] }],
        query: {
          params: {
            id: '',
            organId: '',
            organPath: '',
            organName: '',
            goodsTypeId: '',
            goodsTypePath: '',
            goodsName: '',
            supplierId: '',
            goodsImg: '',
            goodsDescribe: '',
            unit: '',
            unitValue: '',
            productionPlace: '',
            sys: '',
            isDeleted: '',
            quote: '',
            createBy: '',
            createDate: '',
            updateBy: '',
            updateDate: '',
            remark: '',
            assignee: { organPath: '' },
            organIds: []
          },
          goodsPrice: {
            goodsId: '',
            organId: '',
            organPath: '',
            tenantId:'',
            total: 5,
            currentPage: 1,
            pageSize: 10
          },
          goodsSpecification: {
            id: '',
            groupId: '',
            displayArea: '',
            parameterName: '',
            goodsTypeId: '',
            organId: '',
            tenantId: '',
            organPath: '',
            isDeleted: '',
            createBy: '',
            createDate: '',
            updateBy: '',
            updateDate: '',
            remark: '',
            total: 5,
            currentPage: 1,
            pageSize: 10
          },
          goodsSpecificationItem: {
            specificationId: '',
            total: 5,
            currentPage: 1,
            pageSize: 10
          },
          organParams: {
            organPath: ''
          },
          goodsTypesOrganQuery: {
            goodsTypeId: ''
          },
          goodsOrganQuery: {
            id: '',
            organId: '',
            tenantId: ''
          },
          organ: {
            organPath: '',
            organId: '',
            organName: '',
            pageSize: 10,
            total: 0,
            currentPage: 1
          },
          timeValue: '',
          options: [{
            value: '1',
            label: '黄金糕'
          }, {
            value: '2',
            label: '双皮奶'
          }],
          googsImgTypeOptions: [],
          measurementTypeOptions:[],
          measurementUnitOptions:[],
          value: ''
        },
        goodsRule:{
          organId:[
              { required: true, message: '请选择合适的组织机构', trigger: 'change' }
            ],
          tenantId:[
            { required: true, message: '请选择租户', trigger: 'change' }
          ],
          organPath:[ { required: true, message: '请选择合适的组织机构', trigger: 'change' }],
          unitValue:[ { required: true, message: '请填写商品数量', trigger: 'change' }],
          measurementType :[{ required: true,  message: '请选择计量类型', trigger: 'change' }],
          goodsTypeId: [{ required: true,  message: '请选择商品类型', trigger: 'change' }],
          goodsName:[{ required: true,  message: '请输入商品折扣价', trigger: 'change' }],
          supplierId:[{ required: true, message: '请输入商品建议价', trigger: 'change' }],
          goodsImg:[{ required: true,  message: '请上传商品主图片', trigger: 'change' }],
          productionPlace:[{ required: true, message: '请填写商品产地', trigger: 'change' }],
          goodsDescribe:[{ required: true, message: '请填写商品描述', trigger: 'change' }],
          unit:[{ required: true, message: '请填写商品计量单位', trigger: 'change' }]
        },
        goodsPriceRule:{
          organId:[
              { required: true, message: '请选择合适的组织机构', trigger: 'change' }
            ],
          tenantId:[
            { required: true, message: '请选择租户', trigger: 'change' }
          ],
          organPath:[ { required: true, message: '请选择合适的组织机构', trigger: 'change' }],
          unitValue:[ { required: true, message: '请填写商品数量', trigger: 'change' }],
          measurementType :[{ required: true,  message: '请选择计量类型', trigger: 'change' }],
          goodsTypeId: [{ required: true,  message: '请选择商品类型', trigger: 'change' }],
          goodsName:[{ required: true,  message: '请输入商品折扣价', trigger: 'change' }],
          supplierId:[{ required: true, message: '请输入商品建议价', trigger: 'change' }],
          goodsImg:[{ required: true,  message: '请上传商品主图片', trigger: 'change' }],
          productionPlace:[{ required: true, message: '请填写商品产地', trigger: 'change' }],
          goodsDescribe:[{ required: true, message: '请填写商品描述', trigger: 'change' }],
          unit:[{ required: true, message: '请填写商品计量单位', trigger: 'change' }],
          stockCount:[{ required: true, message: '请填写商品库存', trigger: 'change' }]
        }
  
      }
    },
    computed:{
      uploadHeader() {
        return {
            'Authorization' : getToken(),
            'OrganId': getOrganId(),
            'tenantId': getTenantId(),
            'userId': getCurrentLoginUserId()
        }
      }
    }
  
   ,
    created() {
      this.initGoodsTypeTree()
      this.initOrganTree(() => {
        this.setOrganQueryType()
      }, getOrganPath())
      this.initOrganFormTree()
      this.handleFiltTenant()
      this.handleFiltSupplier()
      this.handleBuildGoogsImgTypeOptions()
      this.handleBuildMeasurementTypeOptions()
      this.fetchData()
    },
    methods: {
      translateOrgan(row) {
        return translateOrganId2OrganName(row);
      },
      setOrganQueryType() {
        this.organQueryModel = localStorageUtil.fetch("SYSTEM_SETTING_ORGAN_QUERY_MODEL")
        this.organQueryModelChange(this.organQueryModel)
      },
      typeFormat() {
  
      },
      statusFormat() {
  
      },
      fetchData() {
        this.listLoading = true
        this.createOrganQuery()
        this.currentPage =  this.currentPage || 1
        this.pageSize =  this.pageSize || 10 
        getList(this.query.params, this.currentPage, this.pageSize).then(response => {
          const data = response.data
          this.total = data.totalCount
          this.pageSize = data.pageSize
          this.currentPage = data.currentPage
          this.list = data.entities
          this.listLoading = false
        })
      },
      handleSizeChange(val) {
        this.currentPage = 1
        this.pageSize = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.currentPage = val
        this.fetchData()
  
      },
      createOrganQuery() {
        // 选中了租户
        let tenantSelected = this.$refs['tenantTree'] && this.$refs['tenantTree'].getCheckedNodes() || []
        let organSelected = this.$refs['organTree'] && this.$refs['organTree'].getCheckedNodes() || []
        let that = this
        this.query.params.organId = null
        if (tenantSelected.length && tenantSelected[0]) {
          this.query.params.tenantId = tenantSelected[0].data.id
          if (organSelected.length  && organSelected[0]) {
            if (this.props.multiple) {
              this.query.params.organId = null
              this.query.params.organIds = []
              if (organSelected.length && organSelected[0]) {
                organSelected.forEach(function(element) {
                  that.query.params.organIds.push(element.data.id)
                })
              }
            } else if (organSelected.length  && organSelected[0]) {
              this.query.params.organPath = organSelected[0] && organSelected[0].data.organPath
            }
          } else {
            this.query.params.organId = getOrganId()
          }
        } else {
          this.query.params.tenantId = getTenantId()
          if (organSelected.length && organSelected[0]) {
            if (this.props.multiple) {
              this.query.params.organId = null
              this.query.params.organIds = []
              if (organSelected.length && organSelected[0]) {
                organSelected.forEach(function(element) {
                  that.query.params.organIds.push(element.data.id)
                })
              }
            } else if (organSelected.length && organSelected[0]) {
              this.query.params.organPath = organSelected[0].data.organPath
            }
          } else {
            this.query.params.organId = getOrganId()
          }
        }
      },
      handleGoodsImgEditSave() {
        this.listLoading = true
        this.goodsImg.createBy = getCurrentLoginUserId()
        this.goodsImg.updateBy = getCurrentLoginUserId()
        doUploadImg(this.goodsImg).then(response => {
          let data = response.data
          if (data.successful) {
            this.$message({
              type: 'success',
              message: '操作成功!'
            })
            this.fetchData();
          } else {
            this.$message({
              type: 'info',
              message: data.description || getSystemErrorCode(data.status)
            })
          }
          this.listLoading = false
          this.dialogFormGoodsImgAddVisible = false
        })
      },
      handleGetGoodsImgs(index, row) {
  
        this.listLoading = true
        this.goodsImgUrls = []
        this.goodsImgUrls.push(row.goodsImg)
        getGoodsImgByGoods({ organId: getOrganId(), goodsId:  row.id}).then(response => {
          debugger
          const gateway = response.data
          if (gateway.successful) {
            let data = gateway.data
            for (let i = 0; i < data.length; i++) {
              this.goodsImgUrls.push(data[i].imgUrl)
            }
  
          } else {
            this.$message({
              type: 'info',
              message: data.description || getSystemErrorCode(data.status)
            })
          }
  
          this.listLoading = false
          // 新增弹框标题
          this.dialogStatus = 'showGoodsImgs'
          this.dialogForGoodsImgVisible = true
        })
      },
      handleGoodsImgAdd(index, row) {
  
        // 显示弹框
        this.dialogFormGoodsImgAddVisible = true
  
        this.addForGoodsImgVisible = false
  
        // 新增弹框标题
        this.dialogStatus = 'addGoodsImg'
  
        this.goodsImg.id = ''
        this.goodsImg.goodsId = row.id
        this.goodsImg.imgUrl = ''
        this.goodsImg.imgType = ''
        this.goodsImg.folder = ''
        this.goodsImg.sort = ''
        this.goodsImg.organId = getOrganId()
        this.goodsImg.organPath = getOrganPath()
        this.goodsImg.tenantId = getTenantId()
        this.goodsImg.createBy = ''
        this.goodsImg.createDate = ''
        this.goodsImg.updateBy = ''
        this.goodsImg.updateDate = ''
        this.goodsImg.isDeleted = ''
        this.goodsImg.remark = ''
      },
      handleGetGoodsImg(index, row) {
  
      },
      handleDefaultSelected(selectedNodes) {
        for (let i = 0; i < selectedNodes.length; i++) {
          this.$refs.assigneeTree.setChecked(selectedNodes[i].organId, true, false)
        }
      },
      getCheckedNodes() {
        let nodesInfo = this.$refs['assigneeTree'].getCheckedNodes()
        let that = this
        that.goodsAssignees.assignees = []
        nodesInfo.forEach(function(organ) {
          that.goodsAssignees.assignees.push({
            organId: organ.id,
            tenantId: organ.tenantId,
            organPath: organ.organPath,
            createBy: getCurrentLoginUserId(),
            updateBy: getCurrentLoginUserId()
          })
        })
        assign2Organs(this.goodsAssignees).then(response => {
          const gateway = response.data
          let data = gateway.data
          if (data.successful) {
            this.$message({
              type: 'success',
              message: '操作成功!'
            })
            this.fetchData();
          } else {
            this.$message({
              type: 'info',
              message: data.description || getSystemErrorCode(data.status)
            })
          }
          this.listLoading = false
        })
  
      },
      // 新增
      handleAdd() {
        // 显示弹框
        this.dialogFormVisible = true
        // 新增弹框标题
        this.dialogStatus = 'add'
  
        this.form.id = ''
        this.form.organId = ''
        this.form.organPath = ''
        this.form.organName = ''
        this.form.goodsTypeId = ''
        this.form.goodsTypePath = ''
        this.form.goodsName = ''
        this.form.supplierId = ''
        this.form.goodsImg = ''
        this.form.goodsDescribe = ''
        this.form.unit = ''
        this.form.unitValue = ''
        this.form.productionPlace = ''
        this.form.sys = ''
        this.form.isDeleted = ''
        this.form.quote = ''
        this.form.createBy = ''
        this.form.createDate = ''
        this.form.updateBy = ''
        this.form.updateDate = ''
        this.form.remark = ''
        this.addForVisible = false
      },
      // 编辑
      handleEdit(index, row) {
        console.log(index)
        console.log(row)
        this.form.id = row.id
        this.form.organId = row.organId
        this.form.tenantId = row.tenantId
        this.form.goodsTypeId = row.goodsTypeId
        this.form.organPath = row.organPath
        this.form.organName = row.organName
        this.form.goodsTypePath = row.goodsTypePath
        this.form.goodsName = row.goodsName
        this.form.supplierId = row.supplierId
        this.form.goodsImg = row.goodsImg
        this.form.goodsDescribe = row.goodsDescribe
        this.form.unit = row.unit
        this.form.unitValue = row.unitValue
        this.form.productionPlace = row.productionPlace
        this.form.measurementType=row.measurementType
        this.form.sys = row.sys
        this.form.isDeleted = row.isDeleted
        this.form.quote = row.quote
        this.form.createBy = row.createBy
        this.form.createDate = row.createDate
        this.form.updateBy = row.updateBy
        this.form.updateDate = row.updateDate
        this.form.remark = row.remark
        this.addForVisible = true
        // 显示弹框
        this.dialogFormVisible = true
        // 编辑弹框标题
        this.dialogStatus = 'edit'
      },
      handleDelete(index, row) {
        console.log(index)
        console.log(row)
  
        this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          center: true
        }).then(() => {
          this.listLoading = true
          doDelete(row.id).then(response => {
            const gateway = response.data
            let data = gateway.data
            if (data.successful) {
              this.$message({
                type: 'success',
                message: '操作成功!'
              })
              this.fetchData();
            } else {
              this.$message({
                type: 'info',
                message: data.description || getSystemErrorCode(data.status)
              })
            }
            this.listLoading = false
          })
        }).catch(() => {
          this.listLoading = false
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
      },
      handleEditSave() {
        this.$refs['goodsForm'].validate((valid) => {
            if (valid) {
              this.listLoading = true
              this.form.createBy = getCurrentLoginUserId()
              this.form.updateBy = getCurrentLoginUserId()
              this.form.assignee = { id: getOrganId(), organPath: getOrganPath() }
              doEdit(this.form).then(response => {
                let data = response.data
                if (data.successful) {
                  this.$message({
                    type: 'success',
                    message: '操作成功!'
                  })
                  this.fetchData();
                } else {
                  this.$message({
                    type: 'info',
                    message: data.description || getSystemErrorCode(data.status)
                  })
                }
                this.listLoading = false
                this.dialogFormVisible = false
              })
            }
          });
      },
      handleRemove(file, fileList) {
        console.log(file, fileList);
      },
      handlePreview(file) {
        console.log(file);
      },
      handleExceed(files, fileList) {
        this.$message.warning(`当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
      },
      beforeRemove(file, fileList) {
        return this.$confirm(`确定移除 ${ file.name }？`);
      },
      handleReset() {
        this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          center: true
        }).then(() => {
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
      },
      uploadFileOnSuccess(response, file, fileList) {
        if(!response.data.successful){
          this.$message({
            type: 'warning',
            message: response.description
          })
          return;
        }
        this.form.goodsImg = response.data.data.fileUrl
      },
      uploadImgOnSuccess(response, file, fileList) {
        debugger
        if(!response.data.successful){
          this.$message({
            type: 'warning',
            message: response.description
          })
          return;
        }
        this.goodsImg.imgUrl = response.data.data.fileUrl
      },
  
      initOrganTree(fn, filter, that) {
        this.listLoading = true
        let data = getOrganList()
        if (filter) {
          data = data.filter(function(item, index) {
            return item.organPath.indexOf(filter) >= 0
          })
        }
        if (that && that.organFormOptions && that.organFormOptions.length >= 0) {
          that.organFormOptions = handleBuildTreeDataStruct(data, 'id', 'parentId')
        } else {
          this.organOptions = handleBuildTreeDataStruct(data, 'id', 'parentId')
        }
        this.listLoading = false
        if (fn) {
          fn()
        }
      },
      initOrganFormTree(fn, filter) {
        this.initOrganTree(fn, filter, this)
      },
      setOrganQueryType() {
        this.organQueryModelChange(localStorageUtil.fetch("SYSTEM_SETTING_ORGAN_QUERY_MODEL"))
      },
      selectOrgan(nodes) {
        let nodesInfo = this.$refs['organTree'].getCheckedNodes()
        let that = this
        this.query.params.organPath = ''
        this.query.params.organIds = []
        if (this.props.multiple) {
          this.query.params.organIds = []
          if (nodesInfo.length) {
            nodesInfo.forEach(function(element) {
              that.query.params.organIds.push(element.data.id)
            })
          }
        } else if (nodesInfo.length) {
          this.query.params.organPath = nodesInfo[0].data.organPath
        }
      },
      selectTenant(nodes) {
        debugger
        let nodesInfo = this.$refs['tenantTree'].getCheckedNodes()
        let that = this
        this.query.params.tenantId = ''
        this.query.params.tenantIds = []
        this.query.params.organId = null
        this.query.params.organIds = []
        this.query.params.organPath = null
  
        if (this.tenantProps.multiple) {
          this.query.params.tenantIds = []
          if (nodesInfo.length) {
            nodesInfo.forEach(function(element) {
              that.query.params.tenantIds.push(element.data.id)
            })
          }
        } else if (nodesInfo.length) {
          this.query.params.tenantId = nodesInfo[0].data.id
          this.initOrganTree(function() {
            that.setOrganQueryType()
          }, nodesInfo[0].data.organPath)
        } else {
          this.initOrganTree(function() {
            that.setOrganQueryType()
          })
        }
      },
      chooseTenantForm(nodes) {
        let nodesInfo = this.$refs['tenantTreeForm'].getCheckedNodes()
        this.form.tenantId = null
        let that = this
        if (nodesInfo.length) {
          this.form.tenantId = nodesInfo[0].data.id
          this.initOrganFormTree(function() {
            that.setOrganQueryType()
          }, nodesInfo[0].data.organPath, this.organFormOptions)
        } else {
          this.initOrganFormTree(function() {
            that.setOrganQueryType()
          }, null, this.organFormOptions)
        }
      },
      chooseTenant(form) {
        debugger
        let nodesInfo = this.$refs['tenantTreeForm'].getCheckedNodes()
        form.tenantId = null
        let that = this
        if (nodesInfo.length) {
          form.tenantId = nodesInfo[0].data.id
          this.initOrganFormTree(function() {
            that.setOrganQueryType()
          }, nodesInfo[0].data.organPath, this.organFormOptions)
        } else {
          this.initOrganFormTree(function() {
            that.setOrganQueryType()
          }, null, this.organFormOptions)
        }
      },
      organQueryModelChange(organQueryModel) {
        if (organQueryModel == 'selected') {
          this.props.multiple = true
        } else if (organQueryModel == 'selfAndSub') {
          this.props.multiple = false
        }
      },
      chooseOrganForm(nodes) {
        let nodesInfo = this.$refs['organTreeForm'].getCheckedNodes()
        if (nodesInfo[0]) {
          this.form.organPath = nodesInfo[0].data.organPath
          this.form.organId = nodesInfo[0].data.id
          this.form.tenantId = nodesInfo[0].data.tenantId
        }
      },
      handleFiltTenant() {
        let data = getOrganList()
        this.tenantOptions = data.filter(function(item, index) {
          return item.type == 0 || item.type == 1;
        })
      },
      handleFiltSupplier() {
        debugger
        let data = getOrganList()
        this.supplierOptions = data.filter(function(item, index) {
          return item.type == 99;
        })
      },
      initGoodsTypeTree() {
        this.listLoading = true
        getGoodsTypeTree({ organId: getOrganId() }).then(response => {
          console.log(response)
          const data = response.data.data
          this.goodsTypeTreeOptionData = handleBuildTreeDataStruct(data, 'id', 'parentId')
          this.listLoading = false
        })
      },
      handleQueryGoodsSpecificationCurrentChange(val) {
  
      },
      handleGoodsSpecification2OrganSave() {
  
      },
      handleQueryGoodsSpecificationSizeChange() {
  
      },
      handleAssignOrganSave() {
        this.listLoading = true
        assign2Organs(this.assign2Organs).then(response => {
          const gateway = response.data
          let data = gateway.data
          if (data.successful) {
            this.$message({
              type: 'success',
              message: '操作成功!'
            })
            this.fetchData();
          } else {
            this.$message({
              type: 'info',
              message: data.description || getSystemErrorCode(data.status)
            })
          }
          this.listLoading = false
        })
      },
      handleOrganSelectionChange(val) {
  
        this.assign2Organs.assignees = val
        this.assign2Organs.createBy = getCurrentLoginUserId()
        this.assign2Organs.updateBy = getCurrentLoginUserId()
      },
      getGoodsTypeValue(value) {
        this.goodsTypeValueId = value
        if (value) {
          this.query.params.typePath = value.typePath
        } else {
          this.query.params.typePath = ''
        }
      },
      getValue(value) {
        this.valueId = value
        if (value) {
          this.query.params.organPath = value.organPath
        } else {
          this.query.params.organPath = getOrganPath()
        }
        console.log(this.valueId)
      },
      getSupplier(value) {
        debugger
        let nodesInfo = this.$refs['applyerTree'].getCheckedNodes()
        this.form.supplierId = nodesInfo[0].data.id
      },
      getGoodsType1(value) {
        let nodesInfo = this.$refs['goodsTypeTreeForm'].getCheckedNodes()
        this.form.goodsTypeId = nodesInfo[0].data.id
        this.form.goodsTypePath = nodesInfo[0].data.typePath
      },
      getGoodsType(form) {
        let nodesInfo = this.$refs['goodsTypeTreeForm'].getCheckedNodes()
        form.goodsTypeId = nodesInfo[0].data.id
        form.goodsTypePath = nodesInfo[0].data.typePath
      },
      handleBuildGoogsImgTypeOptions() {
  
        const datas = getDictionary()
        let data = datas.filter(function(item, index) {
          return item.bigType === "GoogsImgType" && item.parentId != '0';
        })
        let googsImgTypeOptions = [];
        for (let i = 0; i < data.length; i++) {
          let option = {}
          option['value'] = data[i].value
          option['label'] = data[i].desc
          googsImgTypeOptions.push(option)
        }
        this.query.googsImgTypeOptions = googsImgTypeOptions
      },
  
      handleBuildMeasurementTypeOptions() {
        const datas = getDictionary()
        let data = datas.filter(function(item, index) {
          return item.bigType === "GoodsUnitOfMeasurement" && item.parentId == '0';
        })
        let measurementTypeOptions = [];
        for (let i = 0; i < data.length; i++) {
          let option = {}
          option['value'] = data[i].code
          option['label'] = data[i].desc
          measurementTypeOptions.push(option)
        }
        this.query.measurementTypeOptions = measurementTypeOptions
      },
      handleInitMeasurementUnitOptions(obj){
        this.handleBuildMeasurementUnitOptions(obj.measurementType)
      },
      handleBuildMeasurementUnitOptions(code) {
        debugger
        const datas = getDictionary()
        let data = datas.filter(function(item, index) {
          return item.bigType === "GoodsUnitOfMeasurement" && item.parentId != '0' && item.nameSpace === ('GOODS_UINT_OF_MEASUREMENT.'+code);
        })
        let measurementUnitOptions = [];
        for (let i = 0; i < data.length; i++) {
          let option = {}
          option['value'] = data[i].value
          option['label'] = data[i].desc
          measurementUnitOptions.push(option)
        }
        this.query.measurementUnitOptions = measurementUnitOptions
      },
  
  
      handleAddGoodsPrice(index, row) {
  
        this.dialogFormGoodsPriceVisible = true
        this.addForGoodsPriceVisible = false
        if(row){
          this.goodsPrice.id = ''
          this.goodsPrice.goodsId = row.id
          this.goodsPrice.goodsName = row.goodsName
          this.goodsPrice.goodsCode = ''
          this.goodsPrice.goodsTypeId = row.goodsTypeId
          this.goodsPrice.goodsTypePath = row.goodsTypePath
          this.goodsPrice.tenantId = row.tenantId || getTenantId()
          this.goodsPrice.organId = row.organId || getOrganId()
          this.goodsPrice.organPath = row.organPath || getOrganPath()
          this.goodsPrice.goodsTypeId = row.goodsTypeId
          this.goodsPrice.goodsTypePath = row.goodsTypePath
          this.goodsPrice.isDeleted = ''
          this.goodsPrice.createBy = getCurrentLoginUserId()
          this.goodsPrice.createDate = ''
          this.goodsPrice.updateBy = getCurrentLoginUserId()
          this.goodsPrice.updateDate = ''
          this.goodsPrice.unit = row.unit
          this.goodsPrice.stockCount = row.unitValue
          this.goodsPrice.remark = ''
          this.goodsPrice.price = ''
        }
        
      },
  
  
      handleModifyGoodsPrice(index, row) {
  
        this.dialogFormGoodsPriceVisible = true
        this.addForGoodsPriceVisible = true
  
        this.goodsPrice.id = row.id
        this.goodsPrice.goodsId = row.goodsId
        this.goodsPrice.goodsName = row.goodsName
        this.goodsPrice.goodsCode = row.goodsCode
        this.goodsPrice.tenantId = row.tenantId || getTenantId()
        this.goodsPrice.organId = row.organId || getOrganId()
        this.goodsPrice.organPath = row.organPath || getOrganPath()
        this.goodsPrice.isDeleted = row.isDeleted
        this.goodsPrice.remark = row.remark
        this.goodsPrice.goodsTypeId = row.goodsTypeId
        this.goodsPrice.goodsTypePath = row.goodsTypePath
        this.goodsPrice.price = row.price
        this.goodsPrice.costPrice = row.costPrice
        this.goodsPrice.discountPrice = row.discountPrice
        this.goodsPrice.suggestedRetailPrice = row.suggestedRetailPrice
        this.goodsPrice.createDate = row.createDate
        this.goodsPrice.updateDate = row.updateDate
      },
  
      handleAddGoodsPriceSave() {
        this.$refs['goodsPriceForm'].validate((valid) => {
            if (valid) {
              this.listLoading = true
              this.goodsPrice.createBy = getCurrentLoginUserId()
              saveGoodsPrice(this.goodsPrice).then(response => {
                let data = response.data
                if (data.successful) {
                  this.$message({
                    type: 'success',
                    message: '操作成功!'
                  })
                  this.fetchData();
                } else {
                  this.$message({
                    type: 'info',
                    message: data.description || getSystemErrorCode(data.status)
                  })
                }
                this.dialogFormGoodsPriceVisible = false
                this.addForGoodsPriceVisible = false
              })
            }
        });
       
      },
      handleShowGoodsPriceList(index, row) {
  
        this.query.goodsPrice.currentPage = 1
        this.query.goodsPrice.pageSize = 10
        this.dialogShowGoodsPriceListAddVisible = true
        this.goodsPriceList = []
        this.query.goodsPrice.goodsId = row.id
        this.query.goodsPrice.organId = row.organId || getOrganId()
        this.query.goodsPrice.organPath = row.organPath || getOrganPath()
        this.query.goodsPrice.tenantId = row.tenantId || getTenantId()
        this.goodsPrice.goodsId = row.goodsId
        this.goodsPrice.goodsName = row.goodsName
        this.goodsPrice.goodsCode = row.goodsCode
        this.goodsPrice.tenantId = row.tenantId || getTenantId()
        this.goodsPrice.organId = row.organId || getOrganId()
        this.goodsPrice.organPath = row.organPath || getOrganPath()
        this.goodsPrice.isDeleted = row.isDeleted
        this.goodsPrice.remark = row.remark
        this.goodsPrice.goodsTypeId = row.goodsTypeId
        this.goodsPrice.goodsTypePath = row.goodsTypePath
        this.goodsPrice.price = row.price
        this.goodsPrice.costPrice = row.costPrice
        this.goodsPrice.discountPrice = row.discountPrice
        this.goodsPrice.suggestedRetailPrice = row.suggestedRetailPrice
        this.goodsPrice.createDate = row.createDate
        this.goodsPrice.updateDate = row.updateDate
  
        this.handleQueryGoodsPrice()
  
      },
      handleGoodsPriceCurrentChange(val) {
  
        this.query.goodsPrice.currentPage = val
        this.handleQueryGoodsPrice()
      },
      handleGoodsPriceSizeChange(val) {
        this.query.goodsPrice.currentPage = 1
        this.query.goodsPrice.pageSize = val
        this.handleQueryGoodsPrice()
  
      },
      handleQueryGoodsPrice() {
        this.listLoading = true
        getGoodsPriceList(this.query.goodsPrice,
          this.query.goodsPrice.currentPage,
          this.query.goodsPrice.pageSize).then(response => {
          const data = response.data
          this.query.goodsPrice.total = data.totalCount
          this.query.goodsPrice.pageSize = data.pageSize
          this.query.goodsPrice.currentPage = data.currentPage
          this.goodsPriceList = data.entities
          this.listLoading = false
        })
      },
      handleDeleteGoodsPrice(index, row) {
  
        console.log(index)
        console.log(row)
        this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          center: true
        }).then(() => {
          deleteGoodsPrice(row.id).then(response => {
            const gateway = response.data
            let data = gateway.data
            if (data.successful) {
              this.$message({
                type: 'success',
                message: '操作成功!'
              })
              this.handleQueryGoodsPrice()
            } else {
              this.$message({
                type: 'info',
                message: data.description || getSystemErrorCode(data.status)
              })
            }
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
      },
  
      selectGoodsType(nodes) {
        let nodesInfo = this.$refs['goodsTypeTree'].getCheckedNodes()
        this.query.params.goodsTypeId = nodesInfo[0].data.id
      },
      selectSupplier(nodes) {
        let nodesInfo = this.$refs['supplierTree'].getCheckedNodes()
        if (nodesInfo.length) {
          this.query.params.supplierId = nodesInfo[0].data.id
        } else {
          this.query.params.supplierId = null
        }
      },
      handleBindGoodsSpecification(index, row) {
        this.dialogFormShowGoodsSpecificationVisible = true
  
      },
      queryGoodsAssignee() {
        queryGoodsAssignee(row.id).then(response => {
          const gateway = response.data
          let data = gateway.data
          if (data.successful) {
            this.$message({
              type: 'success',
              message: '操作成功!'
            })
            this.handleQueryGoodsPrice()
          } else {
            this.$message({
              type: 'info',
              message: data.description || getSystemErrorCode(data.status)
            })
          }
        })
      },
      handleAssignToOrgan(index, row) {
        this.dialogStatus = 'assignOrgan'
        this.goodsAssignees.id = row.id
        this.goodsAssignees.organId = row.organId
        this.goodsAssignees.tenantId = row.tenantId
        this.listLoading = true
        this.dialogFormOrganVisible = true
        this.query.organParams.organPath = getOrganPath()
        this.query.goodsOrganQuery.id = row.id
  
        queryAssigneeOrgan(this.query.organParams).then(response => {
          const pager = response.data
          this.organTree = handleBuildTreeDataStruct(pager.data, 'id', 'parentId')
          this.listLoading = false
          queryAlreadyAssignedOrgans(this.query.goodsOrganQuery).then(response => {
            const data = response.data
            const selectedNodes = data.data
            this.$nextTick(function() {
              this.handleDefaultSelected(selectedNodes)
            })
          })
        })
  
      },
      handleDefaultSelected(selectedNodes) {
        for (let i = 0; i < selectedNodes.length; i++) {
          this.$refs.assigneeTree.setChecked(selectedNodes[i].organId, true, false)
        }
      },
      handleQueryGoodsTypeSpecification(goodsPrice) {
          this.query.goodsSpecification.goodsTypeId = goodsPrice.id
        //TODO 查询租户下，当前登录的用户组织下的商品类型规格项
  
  
      }
    }
  }
  
  </script>
  